//
//  IngScoreView.m
//  NewGame
//
//  Created by wwj on 15/10/13.
//  Copyright © 2015年 wwj. All rights reserved.
//

#import "IngScoreView.h"
#import "StageModel.h"

@interface IngScoreView ()
@property (weak ,nonatomic) IBOutlet UILabel *scoreLabel;
@end

@implementation IngScoreView

+(instancetype)ingScoreView{
    return [[[NSBundle mainBundle] loadNibNamed:@"IngScoreView" owner:nil options:nil] firstObject];
}

-(void)awakeFromNib{
    self.layer.anchorPoint = CGPointMake(0, 1);
    self.transform = CGAffineTransformMakeRotation(-M_PI_2);
    self.layer.position = CGPointMake(-50, 190);
    self.hidden = YES;
}


-(void)begin{
    self.hidden = NO;
    //添加动画
    [UIView animateWithDuration:0.3 animations:^{
        self.transform =CGAffineTransformMakeRotation(M_PI_4/10);
    }];
}

-(void)addScoreWith:(double)score stage:(StageModel *)stageModel{
    NSString *format;
    if (score < 10) {
        format = [NSString stringWithFormat:@"00%@", stageModel.format];
    }
    else if (score < 100){
        format = [NSString stringWithFormat:@"0%@", stageModel.format];
    }
    else{
        format = stageModel.format;
    }
    _scoreLabel.text = [NSString stringWithFormat:format, score];
    
    //添加动画
    CAKeyframeAnimation *transform = [CAKeyframeAnimation animationWithKeyPath:@"transform.translation.x"];
    transform.values = @[@0, @10, @0];
    [self.layer addAnimation:transform forKey:nil];
}

@end
